from django.db import models
from django.contrib.auth.models import User


class polish_line(models.Model) :
    # 记录id，自增
    id = models.AutoField(primary_key=True)
    #生产线id，唯一
    line_id = models.IntegerField(unique=True)
    #生产线名称
    line_name = models.CharField(max_length=200)

class MaintenanceSchedule(models.Model):
    id = models.BigIntegerField(primary_key=True)
    date = models.DateField()
    line_id = models.ForeignKey(polish_line, on_delete=models.CASCADE)
    daily = models.BooleanField(default=False)
    first = models.BooleanField(default=False)
    second = models.BooleanField(default=False)
    overhaul = models.BooleanField(default=False)
    inspection = models.BooleanField(default=False)
    fault = models.BooleanField(default=False)

    class Meta:
        verbose_name = "打磨产线全生命周期运维计划"
        verbose_name_plural = verbose_name

    def __str__(self):
        return str(self.date)

class MaintenanceScheduleContent(models.Model):
    datetime = models.DateTimeField(null=True, blank=True)
    schedule = models.ForeignKey(MaintenanceSchedule, on_delete=models.CASCADE)
    user_id = models.ForeignKey(User, on_delete=models.PROTECT, blank=True, null=True)
    line_id = models.ForeignKey(polish_line, on_delete=models.CASCADE)
    performance = models.BooleanField()
    system = models.CharField(max_length=100)
    part = models.CharField(max_length=100)
    item = models.CharField(max_length=100)
    method = models.TextField()
    consumable = models.TextField(default="无")

    class Type(models.IntegerChoices):
        # 日常维修
        DAILY = 1
        # 一级保养
        FIRST = 2
        # 二级保养
        SECOND = 3
        # 大修
        OVERHAUL = 4
        # 巡检故障维修
        INSPECTION = 5
        # 突发故障
        FAULT = 6

    types = models.IntegerField(choices=Type.choices)

    class Meta:
        verbose_name = "每日运维内容详情"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.item